package com.tarena.lbs.message.web.repository;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tarena.lbs.message.web.mapper.TriggerTemplateMapper;
import com.tarena.lbs.pojo.message.dos.TriggerMsgTemplate;
import com.tarena.lbs.pojo.message.po.TriggerTemplatePO;
import java.util.List;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
@Slf4j
public class TriggerTemplateRepository {
    @Autowired
    private TriggerTemplateMapper triggerTemplateMapper;
    public List<TriggerTemplatePO> getAllTriggerTemplates() {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.orderByDesc("create_at");
        return triggerTemplateMapper.selectList(queryWrapper);
    }

    public void saveTriggerMsgTemplate(TriggerTemplatePO poParam) {
        log.info("新增触发模版数据库入参:{}",poParam);
        triggerTemplateMapper.insert(poParam);
    }

    public TriggerTemplatePO getTriggerTemplatesByUserAction(String actionName) {
        QueryWrapper<TriggerTemplatePO> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("user_action",actionName);
        return triggerTemplateMapper.selectOne(queryWrapper);
    }
}
